package com.lq.educationsystem.student.controller;


import com.lq.educationsystem.common.util.Result;
import com.lq.educationsystem.common.util.ResultBuild;
import com.lq.educationsystem.common.util.ResultPage;
import com.lq.educationsystem.common.util.ResultPageBuild;
import com.lq.educationsystem.common.vo.StudentPageVo;
import com.lq.educationsystem.student.entiy.StudentTb;
import com.lq.educationsystem.student.mapper.StudentTbMapper;
import com.lq.educationsystem.student.service.StudentBaseInterface;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Tag(name = "学生基础课程信息")
@RequestMapping("/student/base")
@RestController
public class StudentBaseController {
    //导入mapper
    @Autowired
    StudentBaseInterface studentBaseInterface;

    //通过id查询
    @Operation(summary = "通过id查询学生信息")
    @PostMapping("/querybyid")
    public Result<StudentTb> queryStudentById(@RequestBody StudentTb studentTb){
        Integer studentId = studentTb.getStudentId();
        //Service

       Result result= studentBaseInterface.queryById(studentId);

       return result;
    }
    //数据插入
    @Operation(summary = "插入学生数据")
    @PostMapping("/insert")
    public Result insertStudentInfo(@RequestBody StudentTb studentTb){

        //新增用户

         studentBaseInterface.insertStudentInfo(studentTb);

        return ResultBuild.buildOk();
    }
    //数据更新
    @Operation(summary = "更新学生信息")
    @PostMapping("/update")
    public Result updateStudentInfo(@RequestBody StudentTb studentTb){

        //新增用户

        studentBaseInterface.updateStudentInfo(studentTb);

        return ResultBuild.buildOk();
    }
    //数据删除
    @Operation(summary = "删除学生信息")
    @PostMapping("/delete")
    public Result deleteStudentInfo(@RequestBody StudentTb studentTb){

        Integer studentId = studentTb.getStudentId();
        //删除用户

        studentBaseInterface.deleteStudentInfo(studentId);

        return ResultBuild.buildOk();
    }

    //查询
    @Operation(summary = "分页查询数据")
    @PostMapping("/query")
    public ResultPage<StudentTb> queryList(@RequestBody StudentPageVo studentPageVo){
        //
        ResultPage<StudentTb> studentTbList = studentBaseInterface.queryList(studentPageVo);

        return studentTbList;
    }

}
